package com.grantheath.erebus.model.nodes
{
	import flash.display.DisplayObjectContainer;

	import com.grantheath.erebus.model.interfaces.IErebusAssetNode;
	import com.grantheath.erebus.model.interfaces.IErebusPageNode;
	import com.grantheath.erebus.model.interfaces.IErebusPageLoader;
	import com.grantheath.erebus.view.interfaces.IErebusPagePreloader;
	import com.grantheath.erebus.view.interfaces.IErebusPage;

	/**
	 * @author grantheath
	 */
	public class ErebusPageNode extends Object implements IErebusPageNode
	{
		private var _pageId : String;
		private var _pageSrc : String;
		private var _pageTitle : String;
		private var _page : IErebusPage;
		private var _treePath : String;
		private var _pageLoaderClass : Class;
		private var _pagePreloaderClass : Class;
		private var _pageLoader : IErebusPageLoader;
		private var _pagePreloader : IErebusPagePreloader;
		private var _pageAssets : Array;
		private var _parent : IErebusPageNode;
		private var _children : Array;
		private var _defaultChild : IErebusPageNode;
		private var _pageLayer : DisplayObjectContainer;
		private var _preloaderLayer : DisplayObjectContainer;
		private var _transitionHandelerClass : Class;
		private var _preloaderTransitionHandelerClass : Class;

		public function ErebusPageNode()
		{
			_children = new Array();
			_pageAssets = new Array();
		}

		public function addChildPageNode(newChild : IErebusPageNode) : void
		{
			_children.push(newChild);
		}

		public function toString() : String 
		{
			return _pageId;
		}

		//GETTERS AND SETTERS
		public function get pageId() : String
		{
			return _pageId;
		}

		public function set pageId(pageId : String) : void
		{
			_pageId = pageId;
		}

		public function get pageSrc() : String
		{
			return _pageSrc;
		}

		public function set pageSrc(pageSrc : String) : void
		{
			_pageSrc = pageSrc;
		}

		public function get pageAssets() : Array
		{
			return _pageAssets;
		}

		public function set pageAssets(pageAssets : Array) : void
		{
			_pageAssets = pageAssets;
		}

		public function get parent() : IErebusPageNode
		{
			return _parent;
		}

		public function set parent(parent : IErebusPageNode) : void
		{
			_parent = parent;
		}

		public function get children() : Array
		{
			return _children;
		}

		public function set children(children : Array) : void
		{
			_children = children;
		}

		public function get pageTitle() : String
		{
			return _pageTitle;
		}

		public function set pageTitle(pageTitle : String) : void
		{
			_pageTitle = pageTitle;
		}

		public function get page() : IErebusPage
		{
			return _page;
		}

		public function set page(page : IErebusPage) : void
		{
			_page = page;
		}

		public function get defaultChild() : IErebusPageNode
		{
			return _defaultChild;
		}

		public function set defaultChild(defaultChild : IErebusPageNode) : void
		{
			_defaultChild = defaultChild;
		}

		public function get treePath() : String
		{
			return _treePath;
		}

		public function set treePath(treePath : String) : void
		{
			_treePath = treePath;
		}

		public function get pagePreloaderClass() : Class
		{
			return _pagePreloaderClass;
		}

		public function set pagePreloaderClass(pagePreloaderClass : Class) : void
		{
			_pagePreloaderClass = pagePreloaderClass;
		}

		public function get pageLoaderClass() : Class
		{
			return _pageLoaderClass;
		}

		public function set pageLoaderClass(pageLoaderClass : Class) : void
		{
			_pageLoaderClass = pageLoaderClass;
		}

		public function get pageLoader() : IErebusPageLoader
		{
			return _pageLoader;
		}

		public function set pageLoader(pageLoader : IErebusPageLoader) : void
		{
			_pageLoader = pageLoader;
		}

		public function get pagePreloader() : IErebusPagePreloader
		{
			return _pagePreloader;
		}

		public function set pagePreloader(pagePreloader : IErebusPagePreloader) : void
		{
			_pagePreloader = pagePreloader;
		}

		public function get isLoaded() : Boolean
		{
			if(!page) {
				return false;
			} else {
				for each(var assetNode : IErebusAssetNode in pageAssets) {
					if(!assetNode.asset) {
						return false;
					}
				}
			}
			return true;
		}

		public function get pageLayer() : DisplayObjectContainer
		{
			return _pageLayer;
		}

		public function set pageLayer(pageLayer : DisplayObjectContainer) : void
		{
			_pageLayer = pageLayer;
		}

		public function get preloaderLayer() : DisplayObjectContainer
		{
			return _preloaderLayer;
		}

		public function set preloaderLayer(preloaderLayer : DisplayObjectContainer) : void
		{
			_preloaderLayer = preloaderLayer;
		}

		public function get transitionHandelerClass() : Class
		{
			return _transitionHandelerClass;
		}

		public function set transitionHandelerClass(transitionHandelerClass : Class) : void
		{
			_transitionHandelerClass = transitionHandelerClass;
		}
		
		public function get preloaderTransitionHandelerClass() : Class
		{
			return _preloaderTransitionHandelerClass;
		}
		
		public function set preloaderTransitionHandelerClass(preloaderTransitionHandelerClass : Class) : void
		{
			_preloaderTransitionHandelerClass = preloaderTransitionHandelerClass;
		}
	}
}
